
var confirmorderInit = function(){};
var html = [];
confirmorderInit.prototype = {
  //加载订单内容
  loadContent:function(data){
  	if($("#main div[id^=supplier_]").length>0){
  		return;
  	}
    html=[];
		var totalCoin=0, totalMoney=0;
		var subCoin=0, subMoney=0;
		var totalQty = 0, subQty=0;
		$.each(data.supplier, function(i, supplier) {
			subCoin=0;
			subMoney=0;
			subQty=0;
	    var tips = { stock_id:supplier.stock_id };
	    html.push('<div  tip='+ JSON.stringify(tips) +' id="supplier_'+ i +'" class="wlxqbg"><div class="wlxqnrbg"><div class="bg-fff ddnybg">');
	    html.push('<div class="ddnybbt mbbottom">');
	    html.push('<p class="shxxbt1"><span>'+ supplier.stock_name +'</span></p>');
	    html.push('</div>');
	    $.each(supplier.goods, function(i, goods) {
		    html.push('<div class="mbbottom  overflow">');
		    html.push('<dl class="cpxqxztop  mtop0">');
		    html.push('<dt><img src="'+ getImageUrl(goods.logo, 65,63) +'"/></dt>');
		    html.push('<dd class="wdgzwz wdgzwz-20">');
		    html.push('<p class="floatr  money2">');
		    if(goods.shop_price != goods.act_price){
		    	html.push('<span class="money">&yen;<label>'+ goods.act_price +'</label></span>');
		    }else{
		    	html.push('<span class="money">&yen;<label>'+ goods.shop_price +'</label></span>');
		    }
		    html.push('+');
		    html.push('<span class="jinbi">');
		    html.push('<b><img src="../../images/jbtub.jpg"/></b>');
		    html.push('<label>'+ goods.coin +'</label>');
		    html.push('</span>');
		    html.push('</p>');
		    html.push(goods.name);
		    html.push('</dd>');
		    html.push('<dd class="huisezi">');
		    html.push('<span class="x2">x<label name="qty">'+ goods.qty +'</label></span>'+goods.spec);
		    html.push('</dd>');
		    html.push('</dl>');
		    html.push('</div>');
	    });
	    html.push('<div class="gmjliuyan gjjsl">');
			html.push('<p class="floatr">');
			html.push('共计'+ supplier.qty +'件商品小计');
			html.push('<span class="money">&yen;'+ supplier.subtotal_money +'</span>');
			html.push('+');
			html.push('<span class="jinbi"><b><img src="../../images/jbtub.jpg"></b>'+ supplier.coin +'</span>');
			html.push('</p>');
	    html.push('</div>');
	    html.push('</div></div></div>');
		});
		
		if(data.usable_coupon.length>0 || data.full_subtract.length>0){
			//优惠活动
			html.push('<div class="wlxqbg">');
			html.push('<div class="wlxqnrbg">');
			html.push('<div class="bg-fff ddnybg">');
			html.push('<div class="wlxqnrbg">');
			if(data.usable_coupon.length>0){			
				//优惠券
				html.push('<p id="selectCoupon" class="wlxqnr">');
				html.push('<span>');
				html.push('<input id="coupon_serial_no" type="hidden" value=""/>');
				html.push('<label class="comfirmOrderTip" id="couponTitle">选择优惠券</label>');
				html.push('<i class="iconfont icon-jiantou-right"></i>');
				html.push('</span>');
				html.push('优惠券');
				html.push('</p>');		
			}
			//满减活动
			if(data.full_subtract.length>0){
				html.push('<p class="wlxqnr">');
				html.push('<span>');
				html.push('<label class="comfirmOrderTip">已节省'+ data.full_subtract[0].discount +'元</label>');
				//html.push('<label class="comfirmOrderTip">已节省2元</label>');
				html.push('</span>');
				html.push('满减');
				html.push('</p>');		
			}
			html.push('</div>');
			html.push('</div>');
			html.push('</div>');		
			html.push('</div>');
		}

		//配送，留言
		html.push('<div class="wlxqbg">');
    html.push('<div class="wlxqnrbg">');
    html.push('<p id="deliver_p" class="wlxqnr  mbbottom">');
    html.push('<span><label class="comfirmOrderTip" id="chosedDeliverType">普通快递</label><i class="iconfont icon-jiantou-right"></i></span>配送');
    html.push('</p>');
    html.push('<p class="wlxqnr  mbbottom">');
    html.push('<span><input name="invoice" style="text-align:right;font-size:1.4rem;" type="text" placeholder="发票抬头" class="mmwb comfirmOrderTip"></span>开具发票');
    html.push('</p>');
    html.push('<p class="wlxqnr  mbbottom">');
    html.push('<input name="remark" type="text" placeholder="给卖家留言" class="mmwb" style="font-size:1.4rem;"/>');
    html.push('</p>');
    html.push('</div>');
    html.push('</div>');
    
    $("#defaultAddress").after(html.join(''));
  },
  //收货地址
  paintAddress: function(data) {
    var data = data.address;
    var i = 0;
    var addressHtml = [];    
    var addressHtml=[];
    var defaultAddress = null;
    if(data.length>0){
	    while (data[i]) {
	      //默认地址显示在页面上
	      if(data[i].def_flag){
	      	defaultAddress = data[i];
	      }
	      //所有地址隐藏起来后面弹出
	      html.push('<div class="shdzbg" name="address" tip="'+ data[i].id +'">');
	      html.push('<div class="shdzk'+ (data[i].def_flag? "":"1") +'">');
	      //html.push('<p class="dwei"><img src="../../images/ditutb'+ (data[i].def_flag? "":"1") +'.png"></p>');
	      html.push('<div style="width:100%" class="shdzhi">');
	      html.push('<p class="sjrmc"><span>15381105360</span>'+ (data[i].def_flag ? '<b class="mrziti">[默认]</b>':'') +'收件人：' + data[i].consignee + '</p>');
	      html.push('<p>' + data[i].region_text + ',' + data[i].address + '</p>');
	      html.push('</div>');
	      html.push('</div>');
	      html.push('</div>');
	      i++;
	    }
	    if(!defaultAddress){
	    	defaultAddress = data[0];
	    }
	    addressHtml.push('<div id="address_id" tip="'+ defaultAddress.id +'" class="shdzk mbtopbottom">');
	    addressHtml.push('<p class="dwei"><img src="../../images/ditutb.png"></p>');
	    addressHtml.push('<div class="shdzhi">');
	    addressHtml.push('<p class="sjrmc"><span>'+ defaultAddress.mobile +'</span><b class="mrziti">[默认]</b>收件人：' + defaultAddress.consignee + '</p>');
	    addressHtml.push('<p>' + defaultAddress.region_text + ',' + defaultAddress.address + '</p>');
	    addressHtml.push('<p class="sjrmc"><span><b class="ybzt"></b><i class="iconfont icon-jiantou2"></i></span><span id="selectAddress">选择其他收货地址</span></p>');
	    addressHtml.push('</div>');
	    addressHtml.push('</div>');	    
   	}else{
			addressHtml.push('<div class="shdzk mbtopbottom" id="addNewAddress">');
			addressHtml.push('<p class="dwei"><img src="../../images/ditutb.png" /></p>');
			addressHtml.push('<p class="floatl add-address" >请添加收货地址</p>');
			addressHtml.push('<div class="floatr rightArrow"><i class="iconfont icon-jiantou-right"></i></div>');
			addressHtml.push('</div>');
   	}
    $("#defaultAddress").html(addressHtml.join(''));
    $("#addressItem").html(html.join(''));
  },
	
	//支付配送
	paingDelivery:function(data){
		var html = [];
		
		html.push('<div class="shop-title">');
		html.push('<div class="item  mbbottom">');
		html.push('<div class="shop-title-content">');
		html.push('<span class="shop-title-name">');
		html.push('<b class="checkboxFour">');
		html.push('<input type="radio" value="1" id="delivery" name="DeliveryType"  class="checkbox-gx">');
		html.push('<label for="delivery"></label>');
		html.push('</b>普通快递');
		html.push('</span>');
		html.push('</div>');
		html.push('</div>');
		html.push('</div>');
		
		var deliveryPoint = data.self_address;
		if(deliveryPoint.length>0){
			html.push('<div class="shop-title">');
			html.push('<div class="item  mbbottom">');
			html.push('<div class="shop-title-content">');
			html.push('<span class="shop-title-name">');
			html.push('<b class="checkboxFour">');
			html.push('<input type="radio" value="2" id="helponself" name="DeliveryType"  class="checkbox-gx"/>');
			html.push('<label for="helponself"></label>');
			html.push('</b>自提货</span>');
			html.push('</div>');
			html.push('</div>');
			html.push('</div>');
			
			html.push('<div class="shop-title mleft25">');	
			var i=0;
			while (deliveryPoint[i]){
				html.push('<div class="item mbbottom">');
				html.push('<div class="shop-title-content">');
				html.push('<span class="shop-title-name">');
				html.push('<b class="checkboxFour">');
				html.push('<input type="radio" name="DeliverAddress" tip="'+ deliveryPoint[i].adress +'" id="checkbox-1-1_organize_'+ deliveryPoint[i].organize_id +'" class="checkbox-gx"/>');
				html.push('<label for="checkbox-1-1_organize_'+ deliveryPoint[i].organize_id +'"></label>');				
				html.push('</b><label id="">'+ deliveryPoint[i].adress +'</label></span>');
				html.push('</div>');
				html.push('</div>');
				i++;
			}
			
			var deliveryPoint = data.delivery_point;
			var mobile = "";
			var consignee = "";
			if(deliveryPoint.length>0){
				$("#commitDelivery").attr("tip", deliveryPoint[0].id);
				mobile = (deliveryPoint.length>0) ? deliveryPoint[0].mobile : '';
				consignee = (deliveryPoint.length>0) ? deliveryPoint[0].consignee : '';
			}			
			html.push('<div class="item mbbottom">');
			html.push('<div class="shop-title-content">');
			html.push('<span class="shop-title-name">');
			html.push('<input id="deliveryPhone" type="text" value="'+ mobile +'" placeholder="请填写配送电话" class="mmwb comfirmOrderTip" style="font-size:1.4rem;">');
			html.push('</span>');
			html.push('<span class="shop-title-name">');
			html.push('<input id="deliveryName" type="text" value="'+ consignee +'" placeholder="请填写收件人姓名" class="mmwb comfirmOrderTip" style="font-size:1.4rem;">');
			html.push('</span>');
			html.push('</div>');
			html.push('</div>');
		
			html.push('</div>');
		}

		$("#deliverPoint").html(html.join(''));
	},
	//加载总价
	loadTotal:function(data){
		$("#total_coin").html(data.total_coin);
		$("#total_money").html(data.total_money);
	}
}